import Vue from 'vue'
import Component from 'vue-class-component'
import { State, Getter, Action, Mutation, namespace } from 'vuex-class'

import OtherComponent from '../other/other'

@Component({
  components: {
    OtherComponent
  },
  template: require('./item.html')
})
export default class ItemComponent extends Vue {
  @State('message') message: any
  @Action('message') actionMessage: any

  beforecreate () {
    console.log('beforecreate')
  }

  created () {
    console.log('created')
  }

  mounted() {
    this.actionMessage()
  }

  updated() {
    console.log('updated')
  }

  beforeDestroy() {
    console.log('beforeDestroy')
  }

  nextTick() {
    console.log('nextTick')
  }

  beforeMount () {
    console.log('beforeMount')
  }

  @State('items') items: any

  // 重写asyncData接口函数
  asyncData ({ store, route }) {

    console.log('process.env', process.env.VUE_ENV);

    if (process.env.VUE_ENV) {
    // 发请求,获取{userInfo:{name:"fake",age:10"}
      console.log(route.params);
      return store.dispatch('fetchItem', route.params.id)
    }
  }
}
